const http = require('http');
const Ws = require('ws').Server;
const server = http.createServer();
server.listen(3000);

let wsServer = new Ws({ server });
wsServer.on('connection', socket => {
  console.log('连接成功');
  // 监听客户端发过来的消息
  socket.on('message', msg => {
    console.log('客户端发送过来的消息：' + msg);
    // 服务器给客户端发送消息

    socket.send(
      JSON.stringify({
        msg: '你好客户端',
        type:'register'
      }),
    );
  });
});
